package com.yonyou.marketing.app.api.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.marketing.common.AppResponse;
import org.marketing.common.constants.ResultMsgConstants;
import org.marketing.common.dto.leads.InsuranceDto;
import org.marketing.common.util.CheckUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.yonyou.marketing.app.api.constant.AppConstant;
import com.yonyou.marketing.app.api.model.AppData;
import com.yonyou.marketing.app.api.model.TtMessage;
import com.yonyou.marketing.app.api.service.AppLoginService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author Administrator
 * @date 2017年6月30日
 */
@RestController
@RequestMapping(value = AppConstant.BASE_PATH + "/" + AppConstant.VERSION)
@Api("APP注册登录API")
public class AppLoginController {

    private Logger          logger = Logger.getLogger(AppLoginController.class);

    @Autowired
    private AppLoginService appLoginService;

    /**
     * 注册验证码
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/sendCheckCodeMessage", method = RequestMethod.POST)
    @ApiOperation(value = "注册验证码", notes = "注册验证码")
    public AppResponse<Map<String, Object>> sendCheckCodeMessage(@RequestParam(required = false, defaultValue = "") String phoneNumber) {
        logger.info("AppLoginController.sendCheckCodeMessage==>start...");
        try {
            appLoginService.sendMsgCode(phoneNumber, AppConstant.SEND_MSG_1);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.sendCheckCodeMessage==>end...");
        }
    }

    /**
     * 校验手机号是否可注册
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/checkPhoneNumberValid", method = RequestMethod.POST)
    @ApiOperation(value = "校验手机号是否可注册", notes = "校验手机号是否可注册")
    public AppResponse<Map<String, Object>> checkPhoneNumberValid(@RequestParam(required = false, defaultValue = "") String phoneNumber,
                                                                  @RequestParam(required = false, defaultValue = "") String checkCode) {
        logger.info("AppLoginController.checkPhoneNumberValid==>start...");
        try {
            appLoginService.checkPhoneNumberValid(phoneNumber, checkCode, AppConstant.SEND_MSG_1);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.checkPhoneNumberValid==>end...");
        }
    }

    /**
     * App用户注册
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/registerAppUser", method = RequestMethod.POST)
    @ApiOperation(value = "App用户注册", notes = "App用户注册")
    public AppResponse<Map<String, Object>> registerAppUser(@RequestParam(required = false, defaultValue = "") String phoneNumber,
                                                            @RequestParam(required = false, defaultValue = "") String checkCode,
                                                            @RequestParam(required = false, defaultValue = "") String password) {
        logger.info("AppLoginController.registerAppUser==>start...");
        try {
            appLoginService.registerAppUser(phoneNumber, checkCode, password);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.registerAppUser==>end...");
        }
    }

    /**
     * App用户登录
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/appUserLogin", method = RequestMethod.POST)
    @ApiOperation(value = "App用户登录", notes = "App用户登录")
    public AppResponse<Map<String, Object>> appUserLogin(@RequestParam(required = false, defaultValue = "") String phoneNumber,
                                                         @RequestParam(required = false, defaultValue = "") String msgCode,
                                                         @RequestParam(required = false, defaultValue = "") String password,
                                                         @RequestParam(required = false, defaultValue = "") String deviceId,
                                                         @RequestParam(required = false, defaultValue = "") String deviceType // 0:安卓
                                                                                                                              // 1:ios
                                                         ,
                                                         @RequestParam(required = false, defaultValue = "") String version) {
        logger.info("AppLoginController.appUserLogin==>start...");
        try {
            Map<String, String> param = new HashMap<>();
            param.put("phone", phoneNumber);
            param.put("msgCode", msgCode);
            param.put("password", password);
            param.put("deviceId", deviceId);
            param.put("deviceType", deviceType);
            param.put("version", version);
            Map<String, Object> map = appLoginService.appUserLogin(param);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, map, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.appUserLogin==>end...");
        }
    }

    /**
     * 手机验证码登陆
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/phoneMsgCode", method = RequestMethod.POST)
    @ApiOperation(value = "手机验证码登陆", notes = "手机验证码登陆")
    public AppResponse<Map<String, Object>> phoneMsgCode(@RequestParam(required = false, defaultValue = "") String phoneNumber) {
        logger.info("AppLoginController.phoneMsgCode==>start...");
        try {
            appLoginService.sendPhoneMsgCodeMessage(phoneNumber);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.phoneMsgCode==>end...");
        }
    }

    /**
     * 忘记密码校验验证码
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/forgetCheckCode", method = RequestMethod.POST)
    @ApiOperation(value = "忘记密码校验验证码", notes = "忘记密码校验验证码")
    public AppResponse<Map<String, Object>> forgetCheckCode(@RequestParam(required = false, defaultValue = "") String phoneNumber,
                                                            @RequestParam(required = false, defaultValue = "") String checkCode) {
        logger.info("AppLoginController.forgetCheckCode==>start...");
        try {
            appLoginService.forgetCheckCode(phoneNumber, checkCode);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.forgetCheckCode==>end...");
        }
    }

    /**
     * 忘记密码校验验证码
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/forgetPassword", method = RequestMethod.POST)
    @ApiOperation(value = "忘记密码校验验证码", notes = "忘记密码校验验证码")
    public AppResponse<Map<String, Object>> forgetPassword(@RequestParam(required = false, defaultValue = "") String phoneNumber) {
        logger.info("AppLoginController.forgetPassword==>start...");
        try {
            appLoginService.sendPasswordForgetMessage(phoneNumber);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.forgetPassword==>end...");
        }
    }

    /**
     * 忘记密码 提交密码
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
    @ApiOperation(value = "忘记密码校验验证码", notes = "忘记密码校验验证码")
    public AppResponse<Map<String, Object>> resetPassword(@RequestParam(required = false, defaultValue = "") String phoneNumber,
                                                          @RequestParam(required = false, defaultValue = "") String password,
                                                          @RequestParam(required = false, defaultValue = "") String checkCode) {
        logger.info("AppLoginController.resetPassword==>start...");
        try {
            appLoginService.resetPassword(phoneNumber, password);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.resetPassword==>end...");
        }
    }

    /**
     * 二次验证使用的验证码
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/buyerTelCheckCode", method = RequestMethod.POST)
    @ApiOperation(value = "二次验证使用的验证码", notes = "二次验证使用的验证码")
    public AppResponse<Map<String, Object>> buyerTelCheckCode(@RequestParam(required = false, defaultValue = "") String vin,
                                                              @RequestParam(required = false, defaultValue = "") String engineNo,
                                                              @RequestParam(required = false, defaultValue = "") String phoneNumber) {
        logger.info("AppLoginController.buyerTelCheckCode==>start...");
        try {
            // 需要判断好是不是给此手机号发短信
            // 根据需要补充

            appLoginService.buyerTelCheckCode(phoneNumber);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.buyerTelCheckCode==>end...");
        }
    }

    /**
     * 手动绑定车辆
     * 
     * @author Administrator
     * @date 2017年11月3日
     * @return
     */
    @RequestMapping(value = "/bindCar", method = RequestMethod.POST)
    @ApiOperation(value = "手动绑定车辆", notes = "手动绑定车辆")
    public AppResponse<Map<String, Object>> bindCar(@RequestParam(required = false, defaultValue = "") String vin,
                                                    @RequestParam(required = false, defaultValue = "") String engineNo,
                                                    @RequestParam(required = false, defaultValue = "") String phoneNumber) {
        logger.info("AppLoginController.buyerTelCheckCode==>start...");
        try {
            Map<String, Object> result = new HashMap<String, Object>();
            result = appLoginService.bindCar(phoneNumber, vin, engineNo);
            logger.info("返回结果为：" + result);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.buyerTelCheckCode==>end...");
        }
    }

    @RequestMapping(value = "/deleteCarOwnerRelation", method = RequestMethod.POST)
    @ApiOperation(value = "删除我的车辆", notes = "删除我的车辆")
    public AppResponse<Map<String, Object>> deleteCarOwnerRelation(@RequestParam(required = false, defaultValue = "") Integer carId,
                                                                   @RequestParam(required = false, defaultValue = "") Integer userId) {
        logger.info("AppLoginController.deleteCarOwnerRelation==>start...");
        try {
            appLoginService.deleteCarOwnerRelation(userId, carId);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.deleteCarOwnerRelation==>end...");
        }
    }

    @RequestMapping(value = "/modifyCarinfo", method = RequestMethod.POST)
    @ApiOperation(value = "更改车辆信息", notes = "更改车辆信息")
    public AppResponse<Map<String, Object>> modifyCarinfo(@RequestParam(required = false, defaultValue = "") String carNickname,
                                                          @RequestParam(required = false, defaultValue = "") String userId,
                                                          @RequestParam(required = false, defaultValue = "") String carId,
                                                          @RequestParam(required = false, defaultValue = "") String carNumber,
                                                          @RequestParam(required = false, defaultValue = "") String maintainSet,
                                                          @RequestParam(required = false, defaultValue = "") String insurer,
                                                          @RequestParam(required = false, defaultValue = "") String vehicleDate,
                                                          @RequestParam(required = false, defaultValue = "") String insuranceEffectiveDate,
                                                          @RequestParam(required = false, defaultValue = "") String vin) {
        logger.info("AppLoginController.modifyCarinfo==>start...");
        Map<String, Object> parmToMap = new HashMap<String, Object>();
        try {
            parmToMap.put("carNickname", carNickname);
            parmToMap.put("userId", userId);
            parmToMap.put("carId", carId);
            parmToMap.put("carNumber", carNumber);
            parmToMap.put("maintainSet", maintainSet);
            parmToMap.put("insurer", insurer);
            parmToMap.put("vehicleDate", vehicleDate);
            parmToMap.put("insuranceEffectiveDate", insuranceEffectiveDate);
            parmToMap.put("vin", vin);
            appLoginService.modifyCarinfo(parmToMap);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.modifyCarinfo==>end...");
        }
    }

    @RequestMapping(value = "/loadInsuranceCompanyInfo", method = RequestMethod.POST)
    @ApiOperation(value = "获取保险公司信息", notes = "获取保险公司信息")
    public AppResponse<List<InsuranceDto>> loadInsuranceCompanyInfo(){
        logger.info("AppLoginController.loadInsuranceCompanyInfo==>start...");
        try{
            List<InsuranceDto> result = appLoginService.loadInsuranceCompanyInfo();
            return new AppResponse<List<InsuranceDto>>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, result, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.loadInsuranceCompanyInfo==>end...");
        }
    }
    
    @RequestMapping(value = "/loadCarinfoList", method = RequestMethod.POST)
    @ApiOperation(value = "获取我的爱车", notes = "获取我的爱车")
    public AppResponse<Map<String, Object>> loadCarinfoList(@RequestParam(required = false, defaultValue = "") Integer carId,
                                                                   @RequestParam(required = false, defaultValue = "") Integer userId) {
        logger.info("AppLoginController.loadCarinfoList==>start...");
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            map = appLoginService.loadCarinfoList(userId, carId);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, map, "");
        } catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.loadCarinfoList==>end...");
        }
    }
    
    @RequestMapping(value = "/loadUserData", method = RequestMethod.POST)
    @ApiOperation(value = "获取用户对应车辆", notes = "获取用户对应车辆")
    public AppResponse<AppData> loadUserData(@RequestParam(required = false, defaultValue = "") Integer userId) {
        logger.info("AppLoginController.loadUserData==>start...");
        AppData appData = new AppData();
        try{
            appData = appLoginService.loadUserData(userId);
            return new AppResponse<AppData>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, appData, "");
        }catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.loadUserData==>end...");
        }
    }
    
    @RequestMapping(value="/getCarOwnerInfo", method = RequestMethod.POST)
    @ApiOperation(value = "获取个人信息", notes = "获取个人信息")
    public AppResponse<AppData> getCarOwnerInfo(@RequestParam(required = false, defaultValue = "") String userId){
        logger.info("AppLoginController.getCarOwnerInfo==>start...");
        AppData appData = new AppData();
        try{
            if (!CheckUtil.NullOrEmpty(userId)){
                appData = appLoginService.getCarOwnerInfo(userId);
            }else{
                appData.setRows(new ArrayList<Object>());
                appData.setTotal(0L);
            }
            return new AppResponse<AppData>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, appData, "");
        }catch (Exception e) {
            logger.error("查询状态发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.getCarOwnerInfo==>end...");
        }
    }
    
    @RequestMapping(value="/updateCarOwnerInfo", method = RequestMethod.POST)
    @ApiOperation(value = "更新车主信息", notes = "更新车主信息")
    public AppResponse<Map<String, Object>> updateCarOwnerInfo(@RequestParam(required = false, defaultValue = "") String userId,
                                                               @RequestParam(required = false, defaultValue = "") String username,
                                                               @RequestParam(required = false, defaultValue = "") Integer sex,
                                                               @RequestParam(required = false, defaultValue = "") String birthday,
                                                               @RequestParam(required = false, defaultValue = "") String address,
                                                               @RequestParam(required = false, defaultValue = "") String driverExpired){
        logger.info("AppLoginController.updateCarOwnerInfo==>start...");
        try{
            appLoginService.updateCarOwnerInfo(userId,username,sex,birthday,address,driverExpired);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        }catch (Exception e) {
            logger.error("更新信息发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.updateCarOwnerInfo==>end...");
        }
    }
    
    @RequestMapping(value="/feedbackInfo" , method=RequestMethod.POST)
    @ApiOperation(value="设置-查看反馈信息", notes="设置-查看反馈信息")
    public AppResponse<AppData> feedbackInfo(@RequestParam(required = false, defaultValue = "") String userId,
                                             @RequestParam(required = false, defaultValue = "") String pageSize,
                                             @RequestParam(required = false, defaultValue = "") String pageNo){
        logger.info("AppLoginController.feedbackInfo==>start...");
        AppData appData = new AppData();
        try{
            appData = appLoginService.feedbackInfo(userId,pageSize,pageNo);
            return new AppResponse<AppData>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, appData, "");
        }catch (Exception e) {
            logger.error("查询发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.feedbackInfo==>end...");
        }
    }
    
    @RequestMapping(value="/feedbackDetail" , method=RequestMethod.POST)
    @ApiOperation(value="设置-查看反馈信息详情" , notes="设置-查看反馈信息详情")
    public AppResponse<AppData> feedbackDetail(@RequestParam(required = false, defaultValue = "") String feedbackId){
        logger.info("AppLoginController.feedbackDetail==>start...");
        AppData appData = new AppData();
        try{
            appData = appLoginService.feedbackDetail(feedbackId);
            return new AppResponse<AppData>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, appData, "");
        }catch (Exception e) {
            logger.error("查询发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        } finally {
            logger.info("AppLoginController.feedbackDetail==>end...");
        }
    }
    
    @RequestMapping(value="/saveFeedback" , method = RequestMethod.POST)
    @ApiOperation(value="设置-提交反馈信息" , notes="设置-提交反馈信息")
    public AppResponse<Map<String,Object>>  saveFeedback(@RequestParam(required = false, defaultValue = "") String userId,
                                                         @RequestParam(required = false, defaultValue = "") String content,
                                                         @RequestParam(required = false, defaultValue = "") String appVersion,
                                                         @RequestParam(required = false, defaultValue = "") String appOsType){
        logger.info("AppLoginController.saveFeedback==>start...");
        try{
            appLoginService.saveFeedback(userId,content,appVersion,appOsType);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        }catch (Exception e) {
            logger.error("查询发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        }finally {
            logger.info("AppLoginController.saveFeedback==>end...");
        }
    }
    
    @RequestMapping(value="/setHint" , method = RequestMethod.POST)
    @ApiOperation(value="设置-消息免打扰" , notes="设置-消息免打扰")
    public AppResponse<Map<String,Object>> setHint(@RequestParam(required = false, defaultValue = "") String userId,
                                                   @RequestParam(required = false, defaultValue = "") String hint_stat){
        logger.info("AppLoginController.setHint==>start...");
        try{
            appLoginService.setHint(userId,hint_stat);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, "");
        }catch (Exception e) {
            logger.error("设置发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        }finally {
            logger.info("AppLoginController.setHint==>end...");
        }
    }

    @RequestMapping(value="/getHint" , method = RequestMethod.POST)
    @ApiOperation(value="设置-获取消息免打扰" , notes="设置-获取消息免打扰")
    public AppResponse<String> getHint(@RequestParam(required = false, defaultValue = "") String userId){
        logger.info("AppLoginController.getHint==>start...");
        try{
            String hint_stat = appLoginService.getHint(userId);
            return new AppResponse<String>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, hint_stat, "");
        }catch (Exception e) {
            logger.error("设置发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        }finally {
            logger.info("AppLoginController.getHint==>end...");
        }
    }
    
    @RequestMapping(value="/setCarOwnerPhoto" , method = RequestMethod.POST)
    @ApiOperation(value="设置头像" , notes="设置头像")
    public AppResponse<String> setCarOwnerPhoto(@RequestParam(required = false, defaultValue = "") String userId,
                                                @RequestParam("photo") MultipartFile photo){
        logger.info("AppLoginController.setCarOwnerPhoto==>start...");
        try{
            String fileUrl = appLoginService.setCarOwnerPhoto(userId,photo);
            return new AppResponse<String>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, fileUrl, "");
        }catch (Exception e) {
            logger.error("设置发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        }finally {
            logger.info("AppLoginController.setCarOwnerPhoto==>end...");
        }
    }
    
    @RequestMapping(value="/checkAccessTokenExpire" , method = RequestMethod.GET)
    @ApiOperation(value="校验APP的TOKEN是否有效" , notes="校验APP的TOKEN是否有效")
    public AppResponse<Boolean> checkAccessTokenExpire(@RequestParam("accessToken") String accessToken,
                                                       @RequestParam("userId") String userId){
        logger.info("AppLoginController.checkAccessTokenExpire==>start...");
        try{
            Boolean flag = appLoginService.checkAccessTokenExpire(accessToken,userId);
            return new AppResponse<Boolean>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, flag, "");
        }catch (Exception e) {
            logger.error("校验发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        }finally {
            logger.info("AppLoginController.checkAccessTokenExpire==>end...");
        }
    }
    @RequestMapping(value="/messageList" , method = RequestMethod.POST)
    @ApiOperation(value="查看我的消息列表" , notes="查看我的消息列表")
    public AppResponse<List<TtMessage>> messageList(@RequestParam("userId") String userId){
        logger.info("AppLoginController.messageList==>start...");
        try{
        	List<TtMessage> flag = appLoginService.messageList(userId);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, flag, "");
        }catch (Exception e) {
            logger.error("校验发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        }finally {
            logger.info("AppLoginController.messageList==>end...");
        }
    }
    @RequestMapping(value="/message" , method = RequestMethod.GET)
    @ApiOperation(value="查看我的消息详情" , notes="查看我的消息详情")
    public AppResponse<List<TtMessage>> message(@RequestParam("id") String id){
        logger.info("AppLoginController.message==>start...");
        try{
        	List<TtMessage> flag = appLoginService.message(id);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, flag, "");
        }catch (Exception e) {
            logger.error("校验发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        }finally {
            logger.info("AppLoginController.message==>end...");
        }
    }
    @RequestMapping(value="/readingFlag" , method = RequestMethod.GET)
    @ApiOperation(value="更新消息状态为已读" , notes="更新消息状态为已读")
    public AppResponse<Map<String, Object>> readingFlag(@RequestParam("id") String id){
        logger.info("AppLoginController.readingFlag==>start...");
        try{
        	Map<String, Object> flag = appLoginService.readingFlag(id);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, flag, "");
        }catch (Exception e) {
            logger.error("校验发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        }finally {
            logger.info("AppLoginController.readingFlag==>end...");
        }
    }
    @RequestMapping(value="/messageCount" , method = RequestMethod.GET)
    @ApiOperation(value="查看未读消息数" , notes="查看未读消息数")
    public AppResponse<Integer> messageCount(@RequestParam("userId") String userId){
        logger.info("AppLoginController.messageCount==>start...");
        try{
        	Integer flag = appLoginService.messageCount(userId);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_SUCCESS, flag, "");
        }catch (Exception e) {
            logger.error("校验发生异常", e);
            return new AppResponse<>(ResultMsgConstants.APP_RESULT_CODE_ERROR, e.getMessage());
        }finally {
            logger.info("AppLoginController.messageCount==>end...");
        }
    }
}
